package com.dyz.swordFingerOffer;

import java.util.ArrayList;
import java.util.Stack;

/**
 * @author: daiyizheng
 * @date: 2021/5/26 13:29
 * @description:
 */
public class printListFromTailToHead06 {

    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        if (listNode==null){
            return arrayList;
        }
        Stack<ListNode> stack = new Stack<ListNode>();
        int size = 0;
        ListNode temp = listNode;
        while (temp!=null){
            stack.push(temp);
            temp = temp.next;
            size++;
        }

        while (size>0){
            arrayList.add(stack.pop().val);
            size--;
        }
        return arrayList;
    }
}

class ListNode {
    int val;
    ListNode next = null;
    ListNode(int val) {
        this.val = val;
    }
}
